<!doctype html>
<html lang="zh-CN">
<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    
    <meta name="referrer" content="no-referrer-when-downgrade">
    

    <title>go-http template | 早起的年轻人</title>
    <meta property="og:title" content="go-http template - 早起的年轻人">
    <meta property="og:type" content="article">
        
    <meta property="article:published_time" content='2021-09-03T23:10:11&#43;08:00'>
        
        
    <meta property="article:modified_time" content='2021-09-03T23:10:11&#43;08:00'>
        
    <meta name="Keywords" content="Flutter，golang,go语言,go语言笔记,飞雪无情,java,android,博客,项目管理,python,软件架构,公众号,小程序">
    <meta name="description" content="go-http template">
        
    <meta name="author" content="luckly">
    <meta property="og:url" content="https://luckly.work/post/go_package/Go%E8%AF%AD%E8%A8%80%E6%A0%87%E5%87%86%E5%BA%93%E4%B9%8Bhttptemplate/">
    <link rel="shortcut icon" href='/favicon.ico'  type="image/x-icon">

    <link rel="stylesheet" href='/css/normalize.css'>
    <link rel="stylesheet" href='/css/style.css'>
    <script type="text/javascript" src="//cdn.bootcdn.net/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

    
    
    
        <link href="https://cdn.bootcdn.net/ajax/libs/fancybox/3.5.7/jquery.fancybox.min.css" rel="stylesheet">
    
    
    
    
        <link rel="stylesheet" href='/css/douban.css'>
    
        <link rel="stylesheet" href='/css/other.css'>
    
</head>

<link rel="stylesheet"
      href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.2.0/styles/default.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.2.0/highlight.min.js"></script>
<body>
    <header id="header" class="clearfix">
    <div class="container">
        <div class="col-group">
            <div class="site-name ">
                
                    <a id="logo" href="https://luckly.work/">
                        早起的年轻人
                    </a>
                
                <p class="description">专注于Flutter、Android、Java、Go语言(golang)、移动互联网、项目管理、软件架构</p>
            </div>
            <div>
                <nav id="nav-menu" class="clearfix">
                    <a class="current" href="https://luckly.work/">首页</a>
                    
                    <a  href="https://luckly.work/categories/" title="分类">分类</a>
                    
                    <a  href="https://luckly.work/tags/" title="标签">标签</a>
                    
                    <a  href="https://luckly.work/archives/" title="归档">归档</a>
                    
                    <a  href="https://luckly.work/about/" title="关于我">关于我</a>
                    
                    <a  href="https://github.com/ITmxs/" title="github">github</a>
                    
                </nav>
            </div>
        </div>
    </div>
</header>

    <div id="body">
        <div class="container">
            <div class="col-group">

                <div class="col-8" id="main">
                    
<div class="res-cons">
    <style type="text/css">
    .post-toc {
        position: fixed;
        width: 200px;
        margin-left: -210px;
        padding: 5px 10px;
        font-family: Athelas, STHeiti, Microsoft Yahei, serif;
        font-size: 12px;
        border: 1px solid rgba(0, 0, 0, .07);
        border-radius: 5px;
        background-color: rgba(255, 255, 255, 0.98);
        background-clip: padding-box;
        -webkit-box-shadow: 1px 1px 2px rgba(0, 0, 0, .125);
        box-shadow: 1px 1px 2px rgba(0, 0, 0, .125);
        word-wrap: break-word;
        white-space: nowrap;
        -webkit-box-sizing: border-box;
        box-sizing: border-box;
        z-index: 999;
        cursor: pointer;
        max-height: 70%;
        overflow-y: auto;
        overflow-x: hidden;
    }

    .post-toc .post-toc-title {
        width: 100%;
        margin: 0 auto;
        font-size: 20px;
        font-weight: 400;
        text-transform: uppercase;
        text-align: center;
    }

    .post-toc .post-toc-content {
        font-size: 15px;
    }

    .post-toc .post-toc-content>nav>ul {
        margin: 10px 0;
    }

    .post-toc .post-toc-content ul {
        padding-left: 20px;
        list-style: square;
        margin: 0.5em;
        line-height: 1.8em;
    }

    .post-toc .post-toc-content ul ul {
        padding-left: 15px;
        display: none;
    }

    @media print,
    screen and (max-width:1057px) {
        .post-toc {
            display: none;
        }
    }
</style>
<div class="post-toc" style="position: absolute; top: 188px;">
    <h2 class="post-toc-title">文章目录</h2>
    <div class="post-toc-content">
        <nav id="TableOfContents">
  <ul>
    <li><a href="#go语言的模板引擎">Go语言的模板引擎</a></li>
    <li><a href="#模板引擎的使用">模板引擎的使用</a>
      <ul>
        <li><a href="#定义模板文件">定义模板文件</a></li>
        <li><a href="#解析模板文件">解析模板文件</a></li>
        <li><a href="#模板渲染">模板渲染</a></li>
        <li><a href="#基本示例">基本示例</a></li>
      </ul>
    </li>
    <li><a href="#模板语法">模板语法</a>
      <ul>
        <li><a href="#heading">{{.}}</a></li>
        <li><a href="#注释">注释</a></li>
        <li><a href="#pipeline">pipeline</a></li>
        <li><a href="#变量">变量</a></li>
        <li><a href="#移除空格">移除空格</a></li>
        <li><a href="#条件判断">条件判断</a></li>
        <li><a href="#range">range</a></li>
        <li><a href="#with">with</a></li>
        <li><a href="#预定义函数">预定义函数</a></li>
        <li><a href="#比较函数">比较函数</a></li>
        <li><a href="#自定义函数">自定义函数</a></li>
        <li><a href="#嵌套template">嵌套template</a></li>
        <li><a href="#block">block</a></li>
        <li><a href="#修改默认的标识符">修改默认的标识符</a></li>
      </ul>
    </li>
    <li><a href="#texttemplate与htmltempalte的区别">text/template与html/tempalte的区别</a></li>
  </ul>
</nav>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        var postToc = $(".post-toc");
        if (postToc.length) {
            var leftPos = $("#main").offset().left;
            if(leftPos<220){
                postToc.css({"width":leftPos-10,"margin-left":(0-leftPos)})
            }

            var t = postToc.offset().top - 20,
                a = {
                    start: {
                        position: "absolute",
                        top: t
                    },
                    process: {
                        position: "fixed",
                        top: 20
                    },
                };
            $(window).scroll(function () {
                var e = $(window).scrollTop();
                e < t ? postToc.css(a.start) : postToc.css(a.process)
            })
        }
    })
</script>
    <article class="post">
        <header>
            <h1 class="post-title">go-http template</h1>
        </header>
        <date class="post-meta meta-date">
            2021年9月3日
        </date>
        
        <div class="post-meta">
            <span>|</span>
            
            <span class="meta-category"><a href='/categories/go'>go</a></span>
            
        </div>
        
        
        <div class="post-meta">
            <span id="busuanzi_container_page_pv">|<span id="busuanzi_value_page_pv"></span><span>
                    阅读</span></span>
        </div>
        
        
        <div class="post-content">
            <p><code>html/template</code>包实现了数据驱动的模板，用于生成可防止代码注入的安全的HTML内容。它提供了和<code>text/template</code>包相同的接口，Go语言中输出HTML的场景都应使用<code>html/template</code>这个包。</p>
<h1 id="模板与渲染">模板与渲染</h1>
<p>在一些前后端不分离的Web架构中，我们通常需要在后端将一些数据渲染到HTML文档中，从而实现动态的网页(网页的布局和样式大致一样，但展示的内容并不一样)效果。</p>
<p>我们这里说的模板可以理解为事先定义好的HTML文档文件，模板渲染的作用机制可以简单理解为文本替换操作–使用相应的数据去替换HTML文档中事先准备好的标记。</p>
<p>很多编程语言的Web框架中都使用各种模板引擎，比如Python语言中Flask框架中使用的jinja2模板引擎。</p>
<h2 id="go语言的模板引擎">Go语言的模板引擎</h2>
<p>Go语言内置了文本模板引擎<code>text/template</code>和用于HTML文档的<code>html/template</code>。它们的作用机制可以简单归纳如下：</p>
<ol>
<li>模板文件通常定义为<code>.tmpl</code>和<code>.tpl</code>为后缀(也可以使用其他的后缀)，必须使用<code>UTF8</code>编码。</li>
<li>模板文件中使用<code>{{</code>和<code>}}</code>包裹和标识需要传入的数据。</li>
<li>传给模板这样的数据就可以通过点号(<code>.</code>)来访问，如果数据是复杂类型的数据，可以通过{ { .FieldName }}来访问它的字段。</li>
<li>除<code>{{</code>和<code>}}</code>包裹的内容外，其他内容均不做修改原样输出。</li>
</ol>
<h2 id="模板引擎的使用">模板引擎的使用</h2>
<p>Go语言模板引擎的使用可以分为三部分：定义模板文件、解析模板文件和模板渲染.</p>
<h3 id="定义模板文件">定义模板文件</h3>
<p>其中，定义模板文件时需要我们按照相关语法规则去编写，后文会详细介绍。</p>
<h3 id="解析模板文件">解析模板文件</h3>
<p>上面定义好了模板文件之后，可以使用下面的常用方法去解析模板文件，得到模板对象：</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-go" data-lang="go"><span style="color:#66d9ef">func</span> (<span style="color:#a6e22e">t</span> <span style="color:#f92672">*</span><span style="color:#a6e22e">Template</span>) <span style="color:#a6e22e">Parse</span>(<span style="color:#a6e22e">src</span> <span style="color:#66d9ef">string</span>) (<span style="color:#f92672">*</span><span style="color:#a6e22e">Template</span>, <span style="color:#66d9ef">error</span>)
<span style="color:#66d9ef">func</span> <span style="color:#a6e22e">ParseFiles</span>(<span style="color:#a6e22e">filenames</span> <span style="color:#f92672">...</span><span style="color:#66d9ef">string</span>) (<span style="color:#f92672">*</span><span style="color:#a6e22e">Template</span>, <span style="color:#66d9ef">error</span>)
<span style="color:#66d9ef">func</span> <span style="color:#a6e22e">ParseGlob</span>(<span style="color:#a6e22e">pattern</span> <span style="color:#66d9ef">string</span>) (<span style="color:#f92672">*</span><span style="color:#a6e22e">Template</span>, <span style="color:#66d9ef">error</span>)
</code></pre></div><p>当然，你也可以使用<code>func New(name string) *Template</code>函数创建一个名为<code>name</code>的模板，然后对其调用上面的方法去解析模板字符串或模板文件。</p>
<h3 id="模板渲染">模板渲染</h3>
<p>渲染模板简单来说就是使用数据去填充模板，当然实际上可能会复杂很多。</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-go" data-lang="go"><span style="color:#66d9ef">func</span> (<span style="color:#a6e22e">t</span> <span style="color:#f92672">*</span><span style="color:#a6e22e">Template</span>) <span style="color:#a6e22e">Execute</span>(<span style="color:#a6e22e">wr</span> <span style="color:#a6e22e">io</span>.<span style="color:#a6e22e">Writer</span>, <span style="color:#a6e22e">data</span> <span style="color:#66d9ef">interface</span>{}) <span style="color:#66d9ef">error</span>
<span style="color:#66d9ef">func</span> (<span style="color:#a6e22e">t</span> <span style="color:#f92672">*</span><span style="color:#a6e22e">Template</span>) <span style="color:#a6e22e">ExecuteTemplate</span>(<span style="color:#a6e22e">wr</span> <span style="color:#a6e22e">io</span>.<span style="color:#a6e22e">Writer</span>, <span style="color:#a6e22e">name</span> <span style="color:#66d9ef">string</span>, <span style="color:#a6e22e">data</span> <span style="color:#66d9ef">interface</span>{}) <span style="color:#66d9ef">error</span>
</code></pre></div><h3 id="基本示例">基本示例</h3>
<h4 id="定义模板文件-1">定义模板文件</h4>
<p>我们按照Go模板语法定义一个<code>hello.tmpl</code>的模板文件，内容如下：</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-html" data-lang="html"><span style="color:#75715e">&lt;!DOCTYPE html&gt;</span>
&lt;<span style="color:#f92672">html</span> <span style="color:#a6e22e">lang</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;zh-CN&#34;</span>&gt;
&lt;<span style="color:#f92672">head</span>&gt;
    &lt;<span style="color:#f92672">meta</span> <span style="color:#a6e22e">charset</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;UTF-8&#34;</span>&gt;
    &lt;<span style="color:#f92672">meta</span> <span style="color:#a6e22e">name</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;viewport&#34;</span> <span style="color:#a6e22e">content</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;width=device-width, initial-scale=1.0&#34;</span>&gt;
    &lt;<span style="color:#f92672">meta</span> <span style="color:#a6e22e">http-equiv</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;X-UA-Compatible&#34;</span> <span style="color:#a6e22e">content</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;ie=edge&#34;</span>&gt;
    &lt;<span style="color:#f92672">title</span>&gt;Hello&lt;/<span style="color:#f92672">title</span>&gt;
&lt;/<span style="color:#f92672">head</span>&gt;
&lt;<span style="color:#f92672">body</span>&gt;
    &lt;<span style="color:#f92672">p</span>&gt;Hello {{.}}&lt;/<span style="color:#f92672">p</span>&gt;
&lt;/<span style="color:#f92672">body</span>&gt;
&lt;/<span style="color:#f92672">html</span>&gt;
</code></pre></div><h4 id="解析和渲染模板文件">解析和渲染模板文件</h4>
<p>然后我们创建一个<code>main.go</code>文件，在其中写下HTTP server端代码如下：</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-go" data-lang="go"><span style="color:#f92672">package</span> <span style="color:#a6e22e">main</span>

<span style="color:#f92672">import</span> (
	<span style="color:#e6db74">&#34;fmt&#34;</span>
	<span style="color:#e6db74">&#34;html/template&#34;</span>
	<span style="color:#e6db74">&#34;net/http&#34;</span>
)

<span style="color:#75715e">// main.go
</span><span style="color:#75715e"></span>
<span style="color:#66d9ef">func</span> <span style="color:#a6e22e">sayHello</span>(<span style="color:#a6e22e">w</span> <span style="color:#a6e22e">http</span>.<span style="color:#a6e22e">ResponseWriter</span>, <span style="color:#a6e22e">r</span> <span style="color:#f92672">*</span><span style="color:#a6e22e">http</span>.<span style="color:#a6e22e">Request</span>) {
	<span style="color:#75715e">//2.解析模板，解析指定文件生成模板对象
</span><span style="color:#75715e"></span>	<span style="color:#a6e22e">tmpl</span>, <span style="color:#a6e22e">err</span> <span style="color:#f92672">:=</span> <span style="color:#a6e22e">template</span>.<span style="color:#a6e22e">ParseFiles</span>(<span style="color:#e6db74">&#34;./hello.tmpl&#34;</span>)
	<span style="color:#66d9ef">if</span> <span style="color:#a6e22e">err</span> <span style="color:#f92672">!=</span> <span style="color:#66d9ef">nil</span> {
		<span style="color:#a6e22e">fmt</span>.<span style="color:#a6e22e">Println</span>(<span style="color:#e6db74">&#34;create template failed, err:&#34;</span>, <span style="color:#a6e22e">err</span>)
		<span style="color:#66d9ef">return</span>
	}
	<span style="color:#75715e">// 3.渲染模板利用给定数据渲染模板，并将结果写入w
</span><span style="color:#75715e"></span>	<span style="color:#a6e22e">name</span><span style="color:#f92672">:=</span><span style="color:#e6db74">&#34;萌小肆&#34;</span>
	<span style="color:#a6e22e">tmpl</span>.<span style="color:#a6e22e">Execute</span>(<span style="color:#a6e22e">w</span>, <span style="color:#a6e22e">name</span>)
}
<span style="color:#66d9ef">func</span> <span style="color:#a6e22e">main</span>() {
	<span style="color:#a6e22e">http</span>.<span style="color:#a6e22e">HandleFunc</span>(<span style="color:#e6db74">&#34;/&#34;</span>, <span style="color:#a6e22e">sayHello</span>)
	<span style="color:#a6e22e">err</span> <span style="color:#f92672">:=</span> <span style="color:#a6e22e">http</span>.<span style="color:#a6e22e">ListenAndServe</span>(<span style="color:#e6db74">&#34;:9090&#34;</span>, <span style="color:#66d9ef">nil</span>)
	<span style="color:#66d9ef">if</span> <span style="color:#a6e22e">err</span> <span style="color:#f92672">!=</span> <span style="color:#66d9ef">nil</span> {
		<span style="color:#a6e22e">fmt</span>.<span style="color:#a6e22e">Println</span>(<span style="color:#e6db74">&#34;HTTP server failed,err:&#34;</span>, <span style="color:#a6e22e">err</span>)
		<span style="color:#66d9ef">return</span>
	}
}
</code></pre></div><p>将上面的<code>main.go</code>文件编译执行，然后使用浏览器访问<code>http://127.0.0.1:9090</code>就能看到页面上显示了“Hello 沙河小王子”。 这就是一个最简单的模板渲染的示例，Go语言模板引擎详细用法请往下阅读。</p>
<h2 id="模板语法">模板语法</h2>
<h3 id="heading">{{.}}</h3>
<p>模板语法都包含在<code>{{</code>和<code>}}</code>中间，其中<code>{{.}}</code>中的点表示当前对象。</p>
<p>当我们传入一个结构体对象时，我们可以根据<code>.</code>来访问结构体的对应字段。例如：</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-go" data-lang="go"><span style="color:#75715e">// main.go
</span><span style="color:#75715e"></span>
<span style="color:#66d9ef">type</span> <span style="color:#a6e22e">UserInfo</span> <span style="color:#66d9ef">struct</span> {
	<span style="color:#a6e22e">Name</span>   <span style="color:#66d9ef">string</span>
	<span style="color:#a6e22e">Gender</span> <span style="color:#66d9ef">string</span>
	<span style="color:#a6e22e">Age</span>    <span style="color:#66d9ef">int</span>
}

<span style="color:#66d9ef">func</span> <span style="color:#a6e22e">sayHello</span>(<span style="color:#a6e22e">w</span> <span style="color:#a6e22e">http</span>.<span style="color:#a6e22e">ResponseWriter</span>, <span style="color:#a6e22e">r</span> <span style="color:#f92672">*</span><span style="color:#a6e22e">http</span>.<span style="color:#a6e22e">Request</span>) {
	<span style="color:#75715e">// 解析指定文件生成模板对象
</span><span style="color:#75715e"></span>	<span style="color:#a6e22e">tmpl</span>, <span style="color:#a6e22e">err</span> <span style="color:#f92672">:=</span> <span style="color:#a6e22e">template</span>.<span style="color:#a6e22e">ParseFiles</span>(<span style="color:#e6db74">&#34;./hello.tmpl&#34;</span>)
	<span style="color:#66d9ef">if</span> <span style="color:#a6e22e">err</span> <span style="color:#f92672">!=</span> <span style="color:#66d9ef">nil</span> {
		<span style="color:#a6e22e">fmt</span>.<span style="color:#a6e22e">Println</span>(<span style="color:#e6db74">&#34;create template failed, err:&#34;</span>, <span style="color:#a6e22e">err</span>)
		<span style="color:#66d9ef">return</span>
	}
	<span style="color:#75715e">// 利用给定数据渲染模板，并将结果写入w
</span><span style="color:#75715e"></span>	<span style="color:#a6e22e">user</span> <span style="color:#f92672">:=</span> <span style="color:#a6e22e">UserInfo</span>{
		<span style="color:#a6e22e">Name</span>:   <span style="color:#e6db74">&#34;小王子&#34;</span>,
		<span style="color:#a6e22e">Gender</span>: <span style="color:#e6db74">&#34;男&#34;</span>,
		<span style="color:#a6e22e">Age</span>:    <span style="color:#ae81ff">18</span>,
	}
	<span style="color:#a6e22e">tmpl</span>.<span style="color:#a6e22e">Execute</span>(<span style="color:#a6e22e">w</span>, <span style="color:#a6e22e">user</span>)
}
</code></pre></div><p>模板文件<code>hello.tmpl</code>内容如下：</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-html" data-lang="html"><span style="color:#75715e">&lt;!DOCTYPE html&gt;</span>
&lt;<span style="color:#f92672">html</span> <span style="color:#a6e22e">lang</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;zh-CN&#34;</span>&gt;
&lt;<span style="color:#f92672">head</span>&gt;
    &lt;<span style="color:#f92672">meta</span> <span style="color:#a6e22e">charset</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;UTF-8&#34;</span>&gt;
    &lt;<span style="color:#f92672">meta</span> <span style="color:#a6e22e">name</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;viewport&#34;</span> <span style="color:#a6e22e">content</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;width=device-width, initial-scale=1.0&#34;</span>&gt;
    &lt;<span style="color:#f92672">meta</span> <span style="color:#a6e22e">http-equiv</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;X-UA-Compatible&#34;</span> <span style="color:#a6e22e">content</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;ie=edge&#34;</span>&gt;
    &lt;<span style="color:#f92672">title</span>&gt;Hello&lt;/<span style="color:#f92672">title</span>&gt;
&lt;/<span style="color:#f92672">head</span>&gt;
&lt;<span style="color:#f92672">body</span>&gt;
    &lt;<span style="color:#f92672">p</span>&gt;Hello {{.Name}}&lt;/<span style="color:#f92672">p</span>&gt;
    &lt;<span style="color:#f92672">p</span>&gt;性别：{{.Gender}}&lt;/<span style="color:#f92672">p</span>&gt;
    &lt;<span style="color:#f92672">p</span>&gt;年龄：{{.Age}}&lt;/<span style="color:#f92672">p</span>&gt;
&lt;/<span style="color:#f92672">body</span>&gt;
&lt;/<span style="color:#f92672">html</span>&gt;
</code></pre></div><p>同理，当我们传入的变量是map时，也可以在模板文件中通过<code>.</code>根据key来取值。</p>
<pre><code>package main

import (
	&quot;fmt&quot;
	&quot;html/template&quot;
	&quot;net/http&quot;
)


type UserInfo struct {
	Name   string
	Gender string
	Age    int
}


func sayHello(w http.ResponseWriter, r *http.Request) {
	//1.定义模板
	//2.解析模板，解析指定文件生成模板对象
	tmpl, err := template.ParseFiles(&quot;./hello.tmpl&quot;)
	if err != nil {
		fmt.Println(&quot;create template failed, err:&quot;, err)
		return
	}
	// 3.渲染模板利用给定数据渲染模板，并将结果写入w
	u1 := UserInfo{
		Name:   &quot;萌小肆&quot;,
		Gender: &quot;男&quot;,
		Age:    18,
	}
	m1:= map[string]interface{}{
		&quot;name&quot;:   &quot;萌小肆&quot;,
		&quot;gender&quot;: &quot;男&quot;,
		&quot;age&quot;:    18,
	}
	//tmpl.Execute(w, user)
	tmpl.Execute(w, map[string]interface{}{
		&quot;u1&quot;:u1,
		&quot;m1&quot;:m1,
	})
}
func main() {

	http.HandleFunc(&quot;/&quot;, sayHello)
	err := http.ListenAndServe(&quot;:9090&quot;, nil)
	if err != nil {
		fmt.Println(&quot;HTTP server failed,err:&quot;, err)
		return
	}
}

</code></pre><pre><code>&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;zh-CN&quot;&gt;
&lt;head&gt;
    &lt;meta charset=&quot;UTF-8&quot;&gt;
    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;
    &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;ie=edge&quot;&gt;
    &lt;title&gt;Hello&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;p&gt;u1&lt;/p&gt;
&lt;p&gt;Hello {{.u1.Name}}&lt;/p&gt;
&lt;p&gt;性别：{{.u1.Gender}}&lt;/p&gt;
&lt;p&gt;年龄：{{.u1.Age}}&lt;/p&gt;
&lt;p&gt;m1&lt;/p&gt;
&lt;p&gt;Hello {{.m1.name}}&lt;/p&gt;
&lt;p&gt;性别：{{.m1.gender}}&lt;/p&gt;
&lt;p&gt;年龄：{{.m1.age}}&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre><h3 id="注释">注释</h3>
<pre><code class="language-template" data-lang="template">{{/* a comment */}}
注释，执行时会忽略。可以多行。注释不能嵌套，并且必须紧贴分界符始止。
</code></pre><h3 id="pipeline">pipeline</h3>
<p><code>pipeline</code>是指产生数据的操作。比如<code>{{.}}</code>、<code>{{.Name}}</code>等。Go的模板语法中支持使用管道符号<code>|</code>链接多个命令，用法和unix下的管道类似：<code>|</code>前面的命令会将运算结果(或返回值)传递给后一个命令的最后一个位置。</p>
<p>**注意：**并不是只有使用了<code>|</code>才是pipeline。Go的模板语法中，<code>pipeline的</code>概念是传递数据，只要能产生数据的，都是<code>pipeline</code>。</p>
<h3 id="变量">变量</h3>
<p>我们还可以在模板中声明变量，用来保存传入模板的数据或其他语句生成的结果。具体语法如下：</p>
<pre><code class="language-template" data-lang="template">$obj := {{.}}
</code></pre><p>其中<code>$obj</code>是变量的名字，在后续的代码中就可以使用该变量了。</p>
<h3 id="移除空格">移除空格</h3>
<p>有时候我们在使用模板语法的时候会不可避免的引入一下空格或者换行符，这样模板最终渲染出来的内容可能就和我们想的不一样，这个时候可以使用<code>{{-</code>语法去除模板内容左侧的所有空白符号， 使用<code>-}}</code>去除模板内容右侧的所有空白符号。</p>
<p>例如：</p>
<pre><code class="language-template" data-lang="template">{{- .Name -}}
</code></pre><p><strong>注意：</strong><code>-</code>要紧挨<code>{{</code>和<code>}}</code>，同时与模板值之间需要使用空格分隔。</p>
<h3 id="条件判断">条件判断</h3>
<p>Go模板语法中的条件判断有以下几种:</p>
<pre><code class="language-template" data-lang="template">{{if pipeline}} T1 {{end}}

{{if pipeline}} T1 {{else}} T0 {{end}}

{{if pipeline}} T1 {{else if pipeline}} T0 {{end}}
</code></pre><h3 id="range">range</h3>
<p>Go的模板语法中使用<code>range</code>关键字进行遍历，有以下两种写法，其中<code>pipeline</code>的值必须是数组、切片、字典或者通道。</p>
<pre><code class="language-template" data-lang="template">{{range pipeline}} T1 {{end}}
如果pipeline的值其长度为0，不会有任何输出

{{range pipeline}} T1 {{else}} T0 {{end}}
如果pipeline的值其长度为0，则会执行T0。
</code></pre><h3 id="with">with</h3>
<pre><code class="language-template" data-lang="template">{{with pipeline}} T1 {{end}}
如果pipeline为empty不产生输出，否则将dot设为pipeline的值并执行T1。不修改外面的dot。

{{with pipeline}} T1 {{else}} T0 {{end}}
如果pipeline为empty，不改变dot并执行T0，否则dot设为pipeline的值并执行T1。
</code></pre><h3 id="预定义函数">预定义函数</h3>
<p>执行模板时，函数从两个函数字典中查找：首先是模板函数字典，然后是全局函数字典。一般不在模板内定义函数，而是使用Funcs方法添加函数到模板里。</p>
<p>预定义的全局函数如下：</p>
<pre><code class="language-template" data-lang="template">and
    函数返回它的第一个empty参数或者最后一个参数；
    就是说&quot;and x y&quot;等价于&quot;if x then y else x&quot;；所有参数都会执行；
or
    返回第一个非empty参数或者最后一个参数；
    亦即&quot;or x y&quot;等价于&quot;if x then x else y&quot;；所有参数都会执行；
not
    返回它的单个参数的布尔值的否定
len
    返回它的参数的整数类型长度
index
    执行结果为第一个参数以剩下的参数为索引/键指向的值；
    如&quot;index x 1 2 3&quot;返回x[1][2][3]的值；每个被索引的主体必须是数组、切片或者字典。
print
    即fmt.Sprint
printf
    即fmt.Sprintf
println
    即fmt.Sprintln
html
    返回与其参数的文本表示形式等效的转义HTML。
    这个函数在html/template中不可用。
urlquery
    以适合嵌入到网址查询中的形式返回其参数的文本表示的转义值。
    这个函数在html/template中不可用。
js
    返回与其参数的文本表示形式等效的转义JavaScript。
call
    执行结果是调用第一个参数的返回值，该参数必须是函数类型，其余参数作为调用该函数的参数；
    如&quot;call .X.Y 1 2&quot;等价于go语言里的dot.X.Y(1, 2)；
    其中Y是函数类型的字段或者字典的值，或者其他类似情况；
    call的第一个参数的执行结果必须是函数类型的值(和预定义函数如print明显不同)；
    该函数类型值必须有1到2个返回值，如果有2个则后一个必须是error接口类型；
    如果有2个返回值的方法返回的error非nil，模板执行会中断并返回给调用模板执行者该错误；
</code></pre><h3 id="比较函数">比较函数</h3>
<p>布尔函数会将任何类型的零值视为假，其余视为真。</p>
<p>下面是定义为函数的二元比较运算的集合：</p>
<pre><code class="language-template" data-lang="template">eq      如果arg1 == arg2则返回真
ne      如果arg1 != arg2则返回真
lt      如果arg1 &lt; arg2则返回真
le      如果arg1 &lt;= arg2则返回真
gt      如果arg1 &gt; arg2则返回真
ge      如果arg1 &gt;= arg2则返回真
</code></pre><p>为了简化多参数相等检测，eq(只有eq)可以接受2个或更多个参数，它会将第一个参数和其余参数依次比较，返回下式的结果：</p>
<pre><code class="language-template" data-lang="template">{{eq arg1 arg2 arg3}}
</code></pre><p>比较函数只适用于基本类型(或重定义的基本类型，如”type Celsius float32”)。但是，整数和浮点数不能互相比较。</p>
<h3 id="自定义函数">自定义函数</h3>
<p>Go的模板支持自定义函数。</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-go" data-lang="go"><span style="color:#66d9ef">func</span> <span style="color:#a6e22e">sayHello</span>(<span style="color:#a6e22e">w</span> <span style="color:#a6e22e">http</span>.<span style="color:#a6e22e">ResponseWriter</span>, <span style="color:#a6e22e">r</span> <span style="color:#f92672">*</span><span style="color:#a6e22e">http</span>.<span style="color:#a6e22e">Request</span>) {
	<span style="color:#a6e22e">htmlByte</span>, <span style="color:#a6e22e">err</span> <span style="color:#f92672">:=</span> <span style="color:#a6e22e">ioutil</span>.<span style="color:#a6e22e">ReadFile</span>(<span style="color:#e6db74">&#34;./hello.tmpl&#34;</span>)
	<span style="color:#66d9ef">if</span> <span style="color:#a6e22e">err</span> <span style="color:#f92672">!=</span> <span style="color:#66d9ef">nil</span> {
		<span style="color:#a6e22e">fmt</span>.<span style="color:#a6e22e">Println</span>(<span style="color:#e6db74">&#34;read html failed, err:&#34;</span>, <span style="color:#a6e22e">err</span>)
		<span style="color:#66d9ef">return</span>
	}
	<span style="color:#75715e">// 自定义一个夸人的模板函数
</span><span style="color:#75715e"></span>	<span style="color:#a6e22e">kua</span> <span style="color:#f92672">:=</span> <span style="color:#66d9ef">func</span>(<span style="color:#a6e22e">arg</span> <span style="color:#66d9ef">string</span>) (<span style="color:#66d9ef">string</span>, <span style="color:#66d9ef">error</span>) {
		<span style="color:#66d9ef">return</span> <span style="color:#a6e22e">arg</span> <span style="color:#f92672">+</span> <span style="color:#e6db74">&#34;真帅&#34;</span>, <span style="color:#66d9ef">nil</span>
	}
	<span style="color:#75715e">// 采用链式操作在Parse之前调用Funcs添加自定义的kua函数
</span><span style="color:#75715e"></span>	<span style="color:#a6e22e">tmpl</span>, <span style="color:#a6e22e">err</span> <span style="color:#f92672">:=</span> <span style="color:#a6e22e">template</span>.<span style="color:#a6e22e">New</span>(<span style="color:#e6db74">&#34;hello&#34;</span>).<span style="color:#a6e22e">Funcs</span>(<span style="color:#a6e22e">template</span>.<span style="color:#a6e22e">FuncMap</span>{<span style="color:#e6db74">&#34;kua&#34;</span>: <span style="color:#a6e22e">kua</span>}).<span style="color:#a6e22e">Parse</span>(string(<span style="color:#a6e22e">htmlByte</span>))
	<span style="color:#66d9ef">if</span> <span style="color:#a6e22e">err</span> <span style="color:#f92672">!=</span> <span style="color:#66d9ef">nil</span> {
		<span style="color:#a6e22e">fmt</span>.<span style="color:#a6e22e">Println</span>(<span style="color:#e6db74">&#34;create template failed, err:&#34;</span>, <span style="color:#a6e22e">err</span>)
		<span style="color:#66d9ef">return</span>
	}

	<span style="color:#a6e22e">user</span> <span style="color:#f92672">:=</span> <span style="color:#a6e22e">UserInfo</span>{
		<span style="color:#a6e22e">Name</span>:   <span style="color:#e6db74">&#34;小王子&#34;</span>,
		<span style="color:#a6e22e">Gender</span>: <span style="color:#e6db74">&#34;男&#34;</span>,
		<span style="color:#a6e22e">Age</span>:    <span style="color:#ae81ff">18</span>,
	}
	<span style="color:#75715e">// 使用user渲染模板，并将结果写入w
</span><span style="color:#75715e"></span>	<span style="color:#a6e22e">tmpl</span>.<span style="color:#a6e22e">Execute</span>(<span style="color:#a6e22e">w</span>, <span style="color:#a6e22e">user</span>)
}
</code></pre></div><p>以上做了一个简单例子：hello.html</p>
<pre><code>&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;zh-CN&quot;&gt;
&lt;head&gt;
    &lt;meta charset=&quot;UTF-8&quot;&gt;
    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;
    &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;ie=edge&quot;&gt;
    &lt;title&gt;Hello&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;p&gt;u1&lt;/p&gt;
&lt;p&gt;Hello {{-    .u1.Name     -}}&lt;/p&gt;
&lt;p&gt;性别：{{.u1.Gender}}&lt;/p&gt;
&lt;p&gt;年龄：{{.u1.Age}}&lt;/p&gt;
&lt;p&gt;m1&lt;/p&gt;
{{/* 2注释，执行时会忽略。可以多行。注释不能嵌套，并且必须紧贴分界符始止。*/}}
&lt;p&gt;Hello {{.m1.name}}&lt;/p&gt;
&lt;p&gt;性别：{{.m1.gender}}&lt;/p&gt;
&lt;p&gt;年龄：{{.m1.age}}&lt;/p&gt;
&lt;hr&gt;
{{$v1:=100}}
{{$age:=.m1.age}}
&lt;hr&gt;
{{if $v1}}
{{$v1}}
{{else}}
啥都么有
{{end}}
&lt;hr&gt;
{{if lt .m1.age 23}}
好好上学
{{else}}
好好工作
{{end}}
&lt;hr&gt;
{{ range  $idx,$hobby:= .hobby}}
     &lt;p&gt;{{ $idx }} -{$hobby}}&lt;/p&gt;
{{else}}
    空空如也
{{end}}
&lt;hr&gt;
&lt;p&gt;m1&lt;/p&gt;
{{/* 2注释，执行时会忽略。可以多行。注释不能嵌套，并且必须紧贴分界符始止。*/}}
{{with .m1}}
&lt;p&gt;Hello {{.name}}&lt;/p&gt;
&lt;p&gt;性别：{{.gender}}&lt;/p&gt;
&lt;p&gt;年龄：{{.age}}&lt;/p&gt;
{{end}}
{{index .hobby 2}}
&lt;/body&gt;
&lt;/html&gt;
</code></pre><p>main.go</p>
<pre><code>package main

import (
	&quot;fmt&quot;
	&quot;html/template&quot;
	&quot;net/http&quot;
)


type UserInfo struct {
	Name   string
	Gender string
	Age    int
}


func sayHello(w http.ResponseWriter, r *http.Request) {
	//1.定义模板
	//2.解析模板，解析指定文件生成模板对象
	tmpl, err := template.ParseFiles(&quot;./hello.tmpl&quot;)
	if err != nil {
		fmt.Println(&quot;create template failed, err:&quot;, err)
		return
	}
	// 3.渲染模板利用给定数据渲染模板，并将结果写入w
	u1 := UserInfo{
		Name:   &quot;萌小肆&quot;,
		Gender: &quot;男&quot;,
		Age:    18,
	}
	m1:= map[string]interface{}{
		&quot;name&quot;:   &quot;萌小肆&quot;,
		&quot;gender&quot;: &quot;男&quot;,
		&quot;age&quot;:    18,
	}
	hobbyList :=[] string{//切片
		&quot;篮球&quot;,
		&quot;双色球&quot;,
		&quot;足球&quot;,
	}
	//tmpl.Execute(w, user)
	tmpl.Execute(w, map[string]interface{}{
		&quot;u1&quot;:u1,
		&quot;m1&quot;:m1,
		&quot;hobby&quot;: hobbyList,
	})
}
func main() {

	http.HandleFunc(&quot;/&quot;, sayHello)
	err := http.ListenAndServe(&quot;:9090&quot;, nil)
	if err != nil {
		fmt.Println(&quot;HTTP server failed,err:&quot;, err)
		return
	}
}

</code></pre><p>我们可以在模板文件<code>hello.tmpl</code>中按照如下方式使用我们自定义的<code>kua</code>函数了。</p>
<pre><code class="language-template" data-lang="template">{{kua .Name}}
</code></pre><h3 id="嵌套template">嵌套template</h3>
<p>我们可以在template中嵌套其他的template。这个template可以是单独的文件，也可以是通过<code>define</code>定义的template。</p>
<p>举个例子： <code>t.tmpl</code>文件内容如下：</p>
<pre><code class="language-template" data-lang="template">&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;zh-CN&quot;&gt;
&lt;head&gt;
    &lt;meta charset=&quot;UTF-8&quot;&gt;
    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;
    &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;ie=edge&quot;&gt;
    &lt;title&gt;tmpl test&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
    
    &lt;h1&gt;测试嵌套template语法&lt;/h1&gt;
    &lt;hr&gt;
    {{template &quot;ul.tmpl&quot;}}
    &lt;hr&gt;
    {{template &quot;ol.tmpl&quot;}}
&lt;/body&gt;
&lt;/html&gt;

{{ define &quot;ol.tmpl&quot;}}
&lt;ol&gt;
    &lt;li&gt;吃饭&lt;/li&gt;
    &lt;li&gt;睡觉&lt;/li&gt;
    &lt;li&gt;打豆豆&lt;/li&gt;
&lt;/ol&gt;
{{end}}
</code></pre><p><code>ul.tmpl</code>文件内容如下：</p>
<pre><code class="language-template" data-lang="template">&lt;ul&gt;
    &lt;li&gt;注释&lt;/li&gt;
    &lt;li&gt;日志&lt;/li&gt;
    &lt;li&gt;测试&lt;/li&gt;
&lt;/ul&gt;
</code></pre><p>我们注册一个<code>templDemo</code>路由处理函数.</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-go" data-lang="go"><span style="color:#a6e22e">http</span>.<span style="color:#a6e22e">HandleFunc</span>(<span style="color:#e6db74">&#34;/tmpl&#34;</span>, <span style="color:#a6e22e">tmplDemo</span>)
</code></pre></div><p><code>tmplDemo</code>函数的具体内容如下：</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-go" data-lang="go"><span style="color:#66d9ef">func</span> <span style="color:#a6e22e">tmplDemo</span>(<span style="color:#a6e22e">w</span> <span style="color:#a6e22e">http</span>.<span style="color:#a6e22e">ResponseWriter</span>, <span style="color:#a6e22e">r</span> <span style="color:#f92672">*</span><span style="color:#a6e22e">http</span>.<span style="color:#a6e22e">Request</span>) {
	<span style="color:#a6e22e">tmpl</span>, <span style="color:#a6e22e">err</span> <span style="color:#f92672">:=</span> <span style="color:#a6e22e">template</span>.<span style="color:#a6e22e">ParseFiles</span>(<span style="color:#e6db74">&#34;./t.tmpl&#34;</span>, <span style="color:#e6db74">&#34;./ul.tmpl&#34;</span>)
	<span style="color:#66d9ef">if</span> <span style="color:#a6e22e">err</span> <span style="color:#f92672">!=</span> <span style="color:#66d9ef">nil</span> {
		<span style="color:#a6e22e">fmt</span>.<span style="color:#a6e22e">Println</span>(<span style="color:#e6db74">&#34;create template failed, err:&#34;</span>, <span style="color:#a6e22e">err</span>)
		<span style="color:#66d9ef">return</span>
	}
	<span style="color:#a6e22e">user</span> <span style="color:#f92672">:=</span> <span style="color:#a6e22e">UserInfo</span>{
		<span style="color:#a6e22e">Name</span>:   <span style="color:#e6db74">&#34;小王子&#34;</span>,
		<span style="color:#a6e22e">Gender</span>: <span style="color:#e6db74">&#34;男&#34;</span>,
		<span style="color:#a6e22e">Age</span>:    <span style="color:#ae81ff">18</span>,
	}
	<span style="color:#a6e22e">tmpl</span>.<span style="color:#a6e22e">Execute</span>(<span style="color:#a6e22e">w</span>, <span style="color:#a6e22e">user</span>)
}
</code></pre></div><p><strong>注意</strong>：在解析模板时，被嵌套的模板一定要在后面解析，例如上面的示例中<code>t.tmpl</code>模板中嵌套了<code>ul.tmpl</code>，所以<code>ul.tmpl</code>要在<code>t.tmpl</code>后进行解析。</p>
<p>main.go</p>
<pre><code>package main

import (
	&quot;fmt&quot;
	&quot;html/template&quot;
	&quot;net/http&quot;
)


func f1(w http.ResponseWriter, r *http.Request) {
	// 自定义一个夸人的模板函数
	//要么只有一个返回值，要么有两个返回值，第二个返回值必须是err类型
	k := func(arg string) (string, error) {
		return arg + &quot;真帅&quot;, nil
	}
	//1.定义模板

	//t,err:=template.New(&quot;f&quot;).ParseFiles(&quot;./f.tmpl&quot;)
	t := template.New(&quot;f.tmpl&quot;) //创建一个名字是f的模板对象
	//告诉模板引擎，我现在多了一个自定义函数 kua
	t.Funcs(template.FuncMap{
		&quot;kua99 &quot; :k,
	})
	//2.解析模板
	t, err := t.ParseFiles(&quot;./f.tmpl&quot;)
	if err != nil {
		fmt.Println(&quot;create template failed, err:%v\n&quot;, err)
		return
	}
	//3.渲染模板
	// 利用给定数据渲染模板，并将结果写入w
	name := &quot;小肆&quot;
	t.Execute(w, name)
}

func demo1(w http.ResponseWriter,r *http.Request){
	//定义模板
	//解析模板
	t,err:=template.ParseFiles(&quot;./t.tmpl&quot;,&quot;./u1.tmpl&quot;)
	if err !=nil{
		fmt.Println(&quot;cteate template failed err: %v\n&quot;,err)
		return
	}
	name:=&quot;茜茜&quot;
	t.Execute(w,name)
	//渲染模板


}
func main() {

	//http.HandleFunc(&quot;/&quot;, f1)
	http.HandleFunc(&quot;/tmpldemo&quot;, demo1)
	err := http.ListenAndServe(&quot;:9090&quot;, nil)
	if err != nil {
		fmt.Println(&quot;HTTP server failed,err:&quot;, err)
		return
	}
}

</code></pre><h3 id="block">block</h3>
<pre><code class="language-template" data-lang="template">{{block &quot;name&quot; pipeline}} T1 {{end}}
</code></pre><p><code>block</code>是定义模板<code>{{define &quot;name&quot;}} T1 {{end}}</code>和执行<code>{{template &quot;name&quot; pipeline}}</code>缩写，典型的用法是定义一组根模板，然后通过在其中重新定义块模板进行自定义。</p>
<p>定义一个根模板<code>templates/base.tmpl</code>，内容如下：</p>
<pre><code class="language-template" data-lang="template">&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;zh-CN&quot;&gt;
&lt;head&gt;
    &lt;title&gt;Go Templates&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div class=&quot;container-fluid&quot;&gt;
    {{block &quot;content&quot; . }}{{end}}
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre><p>然后定义一个<code>templates/index.tmpl</code>，”继承”<code>base.tmpl</code>：</p>
<pre><code class="language-tempalte" data-lang="tempalte">{{template &quot;base.tmpl&quot;}}

{{define &quot;content&quot;}}
    &lt;div&gt;Hello world!&lt;/div&gt;
{{end}}
</code></pre><p>然后使用<code>template.ParseGlob</code>按照正则匹配规则解析模板文件，然后通过<code>ExecuteTemplate</code>渲染指定的模板：</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-go" data-lang="go"><span style="color:#66d9ef">func</span> <span style="color:#a6e22e">index</span>(<span style="color:#a6e22e">w</span> <span style="color:#a6e22e">http</span>.<span style="color:#a6e22e">ResponseWriter</span>, <span style="color:#a6e22e">r</span> <span style="color:#f92672">*</span><span style="color:#a6e22e">http</span>.<span style="color:#a6e22e">Request</span>){
	<span style="color:#a6e22e">tmpl</span>, <span style="color:#a6e22e">err</span> <span style="color:#f92672">:=</span> <span style="color:#a6e22e">template</span>.<span style="color:#a6e22e">ParseGlob</span>(<span style="color:#e6db74">&#34;templates/*.tmpl&#34;</span>)
	<span style="color:#66d9ef">if</span> <span style="color:#a6e22e">err</span> <span style="color:#f92672">!=</span> <span style="color:#66d9ef">nil</span> {
		<span style="color:#a6e22e">fmt</span>.<span style="color:#a6e22e">Println</span>(<span style="color:#e6db74">&#34;create template failed, err:&#34;</span>, <span style="color:#a6e22e">err</span>)
		<span style="color:#66d9ef">return</span>
	}
	<span style="color:#a6e22e">err</span> = <span style="color:#a6e22e">tmpl</span>.<span style="color:#a6e22e">ExecuteTemplate</span>(<span style="color:#a6e22e">w</span>, <span style="color:#e6db74">&#34;index.tmpl&#34;</span>, <span style="color:#66d9ef">nil</span>)
	<span style="color:#66d9ef">if</span> <span style="color:#a6e22e">err</span> <span style="color:#f92672">!=</span> <span style="color:#66d9ef">nil</span> {
		<span style="color:#a6e22e">fmt</span>.<span style="color:#a6e22e">Println</span>(<span style="color:#e6db74">&#34;render template failed, err:&#34;</span>, <span style="color:#a6e22e">err</span>)
		<span style="color:#66d9ef">return</span>
	}
}
</code></pre></div><p>如果我们的模板名称冲突了，例如不同业务线下都定义了一个<code>index.tmpl</code>模板，我们可以通过下面两种方法来解决。</p>
<ol>
<li>在模板文件开头使用<code>{{define 模板名}}</code>语句显式的为模板命名。</li>
<li>可以把模板文件存放在<code>templates</code>文件夹下面的不同目录中，然后使用<code>template.ParseGlob(&quot;templates/**/*.tmpl&quot;)</code>解析模板。</li>
</ol>
<h3 id="修改默认的标识符">修改默认的标识符</h3>
<p>Go标准库的模板引擎使用的花括号<code>{{</code>和<code>}}</code>作为标识，而许多前端框架(如<code>Vue</code>和 <code>AngularJS</code>)也使用<code>{{</code>和<code>}}</code>作为标识符，所以当我们同时使用Go语言模板引擎和以上前端框架时就会出现冲突，这个时候我们需要修改标识符，修改前端的或者修改Go语言的。这里演示如何修改Go语言模板引擎默认的标识符：</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-go" data-lang="go"><span style="color:#a6e22e">template</span>.<span style="color:#a6e22e">New</span>(<span style="color:#e6db74">&#34;test&#34;</span>).<span style="color:#a6e22e">Delims</span>(<span style="color:#e6db74">&#34;{[&#34;</span>, <span style="color:#e6db74">&#34;]}&#34;</span>).<span style="color:#a6e22e">ParseFiles</span>(<span style="color:#e6db74">&#34;./t.tmpl&#34;</span>)
</code></pre></div><h2 id="texttemplate与htmltempalte的区别">text/template与html/tempalte的区别</h2>
<p><code>html/template</code>针对的是需要返回HTML内容的场景，在模板渲染过程中会对一些有风险的内容进行转义，以此来防范跨站脚本攻击。</p>
<p>例如，我定义下面的模板文件：</p>
<pre><code class="language-template" data-lang="template">&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;zh-CN&quot;&gt;
&lt;head&gt;
    &lt;meta charset=&quot;UTF-8&quot;&gt;
    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;
    &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;ie=edge&quot;&gt;
    &lt;title&gt;Hello&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
    {{.}}
&lt;/body&gt;
&lt;/html&gt;
</code></pre><p>这个时候传入一段JS代码并使用<code>html/template</code>去渲染该文件，会在页面上显示出转义后的JS内容。 <code>&lt;script&gt;alert('嘿嘿嘿')&lt;/script&gt;</code> 这就是<code>html/template</code>为我们做的事。</p>
<p>但是在某些场景下，我们如果相信用户输入的内容，不想转义的话，可以自行编写一个safe函数，手动返回一个<code>template.HTML</code>类型的内容。示例如下：</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-go" data-lang="go"><span style="color:#66d9ef">func</span> <span style="color:#a6e22e">xss</span>(<span style="color:#a6e22e">w</span> <span style="color:#a6e22e">http</span>.<span style="color:#a6e22e">ResponseWriter</span>, <span style="color:#a6e22e">r</span> <span style="color:#f92672">*</span><span style="color:#a6e22e">http</span>.<span style="color:#a6e22e">Request</span>){
	<span style="color:#a6e22e">tmpl</span>,<span style="color:#a6e22e">err</span> <span style="color:#f92672">:=</span> <span style="color:#a6e22e">template</span>.<span style="color:#a6e22e">New</span>(<span style="color:#e6db74">&#34;xss.tmpl&#34;</span>).<span style="color:#a6e22e">Funcs</span>(<span style="color:#a6e22e">template</span>.<span style="color:#a6e22e">FuncMap</span>{
		<span style="color:#e6db74">&#34;safe&#34;</span>: <span style="color:#66d9ef">func</span>(<span style="color:#a6e22e">s</span> <span style="color:#66d9ef">string</span>)<span style="color:#a6e22e">template</span>.<span style="color:#a6e22e">HTML</span> {
			<span style="color:#66d9ef">return</span> <span style="color:#a6e22e">template</span>.<span style="color:#a6e22e">HTML</span>(<span style="color:#a6e22e">s</span>)
		},
	}).<span style="color:#a6e22e">ParseFiles</span>(<span style="color:#e6db74">&#34;./xss.tmpl&#34;</span>)
	<span style="color:#66d9ef">if</span> <span style="color:#a6e22e">err</span> <span style="color:#f92672">!=</span> <span style="color:#66d9ef">nil</span> {
		<span style="color:#a6e22e">fmt</span>.<span style="color:#a6e22e">Println</span>(<span style="color:#e6db74">&#34;create template failed, err:&#34;</span>, <span style="color:#a6e22e">err</span>)
		<span style="color:#66d9ef">return</span>
	}
	<span style="color:#a6e22e">jsStr</span> <span style="color:#f92672">:=</span> <span style="color:#e6db74">`&lt;script&gt;alert(&#39;嘿嘿嘿&#39;)&lt;/script&gt;`</span>
	<span style="color:#a6e22e">err</span> = <span style="color:#a6e22e">tmpl</span>.<span style="color:#a6e22e">Execute</span>(<span style="color:#a6e22e">w</span>, <span style="color:#a6e22e">jsStr</span>)
	<span style="color:#66d9ef">if</span> <span style="color:#a6e22e">err</span> <span style="color:#f92672">!=</span> <span style="color:#66d9ef">nil</span> {
		<span style="color:#a6e22e">fmt</span>.<span style="color:#a6e22e">Println</span>(<span style="color:#a6e22e">err</span>)
	}
}
</code></pre></div><p>这样我们只需要在模板文件不需要转义的内容后面使用我们定义好的safe函数就可以了。</p>
<pre><code class="language-template" data-lang="template">{{ . | safe }}
</code></pre>
        </div>

        
<div class="post-archive">
    <ul class="post-copyright">
        <li><strong>原文作者：</strong><a rel="author" href="https://luckly.work/">luckly</a></li>
        <li style="word-break:break-all"><strong>原文链接：</strong><a href="https://luckly.work/post/go_package/Go%E8%AF%AD%E8%A8%80%E6%A0%87%E5%87%86%E5%BA%93%E4%B9%8Bhttptemplate/">https://luckly.work/post/go_package/Go%E8%AF%AD%E8%A8%80%E6%A0%87%E5%87%86%E5%BA%93%E4%B9%8Bhttptemplate/</a></li>
        <li><strong>版权声明：</strong>本作品采用<a rel="license" href="https://creativecommons.org/licenses/by-nc-nd/4.0/">知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议</a>进行许可，非商业转载请注明出处（作者，原文链接），商业转载请联系作者获得授权。</li>
    </ul>
</div>
<br/>



        

<div class="post-archive">
    <h2>See Also</h2>
    <ul class="listing">
        
        <li><a href="/post/go_package/strconv/">Go-strconv</a></li>
        
        <li><a href="/post/go_package/time/">Go-time</a></li>
        
        <li><a href="/post/go_basic/go%E8%AF%AD%E8%A8%80%E5%9F%BA%E7%A1%80%E4%B9%8Bmap/">Go语言基础之map</a></li>
        
        <li><a href="/post/go_basic/go%E8%AF%AD%E8%A8%80%E5%9F%BA%E7%A1%80%E4%B9%8B%E5%87%BD%E6%95%B0/">Go语言基础之函数</a></li>
        
        <li><a href="/post/go_basic/go%E8%AF%AD%E8%A8%80%E5%9F%BA%E7%A1%80%E4%B9%8B%E5%88%87%E7%89%87/">Go语言基础之切片</a></li>
        
    </ul>
</div>


        <div class="post-meta meta-tags">
            
            <ul class="clearfix">
                
                <li><a href='/tags/go'>go</a></li>
                
            </ul>
            
        </div>
    </article>
    
    

    
    
    <div class="post bg-white">
      <script src="https://utteranc.es/client.js"
            repo= "https://github.com/ITmxs/repo"
            issue-term="pathname"
            theme="github-light"
            crossorigin="anonymous"
            async>
      </script>
    </div>
    
</div>

                    <footer id="footer">
    <div>
        &copy; 2021 <a href="https://luckly.work/">早起的年轻人 By luckly</a>
        
        | <a rel="nofollow" target="_blank" href="http://beian.miit.gov.cn/">粤ICP备2021号-1</a>
        
    </div>
    <br />
    <div>
        <div class="github-badge">
            <a href="https://juejin.cn/user/3843548384077192" target="_black" rel="nofollow"><span class="badge-subject">Powered by</span><span class="badge-value bg-blue">掘金</span></a>
        </div>
        <div class="github-badge">
            <a href="https://space.bilibili.com/480883651" target="_black"><span class="badge-subject">Design by</span><span class="badge-value bg-brightgreen">早起的年轻人</span></a>
        </div>
        <div class="github-badge">
            <a href="https://cloud.tencent.com/developer/user/6702670" target="_black"><span class="badge-subject">Theme</span><span class="badge-value bg-yellowgreen">云社区</span></a>
        </div>
    </div>
</footer>


    
    <script type="text/javascript">
        window.MathJax = {
            tex2jax: {
                inlineMath: [['$', '$']],
                processEscapes: true
                }
            };
    </script>
    <script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML' async></script><script src="https://cdn.bootcdn.net/ajax/libs/fancybox/3.5.7/jquery.fancybox.min.js"></script>

<a id="rocket" href="#top"></a>
<script type="text/javascript" src='/js/totop.js?v=0.0.0' async=""></script>



    <script type="text/javascript" src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" async></script>




    <script src='/js/douban.js'></script>
    <script src="/js/copy-to-clipboard.js"></script>

                </div>

                <div id="secondary">
    <section class="widget">
        <form id="search" action='https://luckly.work/search/' method="get" accept-charset="utf-8" target="_blank" _lpchecked="1">
      
      <input type="text" name="q" maxlength="20" placeholder="Search">
      <input type="hidden" name="sitesearch" value="https://luckly.work/">
      <button type="submit" class="submit icon-search"></button>
</form>
    </section>
    
    <section class="widget">
        <h3 class="widget-title">最近文章</h3>
<ul class="widget-list">
    
    <li>
        <a href="https://luckly.work/post/nginx/nginx%E6%96%87%E4%BB%B6%E5%86%85%E5%AE%B9/" title="Nginx文件内容">Nginx文件内容</a>
    </li>
    
    <li>
        <a href="https://luckly.work/post/nginx/nginx%E6%9E%81%E7%AE%80%E6%95%99%E7%A8%8B/" title="Nginx极简教程">Nginx极简教程</a>
    </li>
    
    <li>
        <a href="https://luckly.work/post/nginx/%E5%8D%81%E5%88%86%E9%92%9F%E5%85%A5%E9%97%A8nginx/" title="十分钟入门Nginx">十分钟入门Nginx</a>
    </li>
    
    <li>
        <a href="https://luckly.work/post/go/Goland%E8%BF%9C%E7%A8%8B%E5%BC%80%E5%8F%91%E9%85%8D%E7%BD%AE/" title="Goland远程开发配置">Goland远程开发配置</a>
    </li>
    
    <li>
        <a href="https://luckly.work/post/%E8%AF%BB%E4%B9%A6/%E5%9F%9F%E5%90%8D%E8%A7%A3%E6%9E%90/" title="域名解析">域名解析</a>
    </li>
    
    <li>
        <a href="https://luckly.work/post/git/%E6%8F%90%E4%BA%A4%E8%BF%87%E7%A8%8B%E7%9C%81%E7%95%A5%E6%9F%90%E4%BA%9B%E6%96%87%E4%BB%B6/" title="提交过程省略某些文件">提交过程省略某些文件</a>
    </li>
    
    <li>
        <a href="https://luckly.work/post/flutter_tips/Flutter_DropdownButton%E7%A4%BA%E4%BE%8B/" title="Flutter_DropdownButton示例">Flutter_DropdownButton示例</a>
    </li>
    
    <li>
        <a href="https://luckly.work/post/flutter_tips/Flutter_ExpansionPanelList%E5%92%8CExpansionPanelList.radio%E7%A4%BA%E4%BE%8B/" title="Flutter_ExpansionPanelList和ExpansionPanelList">Flutter_ExpansionPanelList和ExpansionPanelList</a>
    </li>
    
    <li>
        <a href="https://luckly.work/post/flutter_tips/Flutter%E5%BE%AE%E4%BF%A1%E5%88%86%E4%BA%AB%E9%93%BE%E6%8E%A5%E8%B7%B3%E5%9B%9EApp%E6%8C%87%E5%AE%9A%E9%A1%B5%E9%9D%A2/" title="Flutter微信分享链接跳回App指定页面">Flutter微信分享链接跳回App指定页面</a>
    </li>
    
    <li>
        <a href="https://luckly.work/post/%E4%BF%A1%E6%81%AF%E7%B3%BB%E7%BB%9F/%E5%A4%96%E5%8C%85%E5%8F%AF%E8%83%BD%E7%9A%84%E9%97%AE%E9%A2%98/" title="外包可能的问题">外包可能的问题</a>
    </li>
    
</ul>
    </section>

    

    <section class="widget">
        <h3 class="widget-title"><a href='/categories/'>分类</a></h3>
<ul class="widget-list">
    
    <li><a href="https://luckly.work/categories/Flutter/">Flutter (326)</a></li>
    
    <li><a href="https://luckly.work/categories/IT/">IT (2)</a></li>
    
    <li><a href="https://luckly.work/categories/Kotlin/">Kotlin (2)</a></li>
    
    <li><a href="https://luckly.work/categories/Mysql/">Mysql (1)</a></li>
    
    <li><a href="https://luckly.work/categories/nginx/">nginx (1)</a></li>
    
    <li><a href="https://luckly.work/categories/Vue/">Vue (6)</a></li>
    
    <li><a href="https://luckly.work/categories/YouTube%E8%A7%86%E9%A2%91%E4%B8%8B%E8%BD%BD/">YouTube视频下载 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/android/">android (6)</a></li>
    
    <li><a href="https://luckly.work/categories/dart/">dart (96)</a></li>
    
    <li><a href="https://luckly.work/categories/Flutter/">Flutter (28)</a></li>
    
    <li><a href="https://luckly.work/categories/gin/">gin (25)</a></li>
    
    <li><a href="https://luckly.work/categories/git/">git (4)</a></li>
    
    <li><a href="https://luckly.work/categories/Go/">Go (102)</a></li>
    
    <li><a href="https://luckly.work/categories/gorm/">gorm (4)</a></li>
    
    <li><a href="https://luckly.work/categories/grpc/">grpc (1)</a></li>
    
    <li><a href="https://luckly.work/categories/html/">html (3)</a></li>
    
    <li><a href="https://luckly.work/categories/ios/">ios (1)</a></li>
    
    <li><a href="https://luckly.work/categories/linux/">linux (1)</a></li>
    
    <li><a href="https://luckly.work/categories/nginx/">nginx (6)</a></li>
    
    <li><a href="https://luckly.work/categories/python/">python (35)</a></li>
    
    <li><a href="https://luckly.work/categories/read/">读书笔记 (6)</a></li>
    
    <li><a href="https://luckly.work/categories/redis/">redis (2)</a></li>
    
    <li><a href="https://luckly.work/categories/%E4%B8%AA%E4%BA%BA%E8%B5%84%E6%96%99/">个人资料 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E4%B9%A6%E5%8D%95/">书单 (8)</a></li>
    
    <li><a href="https://luckly.work/categories/%E4%B9%A6%E8%AF%84/">书评 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E4%BF%A1%E6%81%AF%E7%B3%BB%E7%BB%9F%E7%AE%A1%E7%90%86%E5%B8%88/">信息系统管理师 (19)</a></li>
    
    <li><a href="https://luckly.work/categories/%E4%BF%A1%E6%81%AF%E7%B3%BB%E7%BB%9F%E9%A1%B9%E7%9B%AE%E7%AE%A1%E7%90%86%E5%B8%88/">信息系统项目管理师 (25)</a></li>
    
    <li><a href="https://luckly.work/categories/%E5%8E%9F%E5%88%99/">原则 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E5%8E%9F%E7%94%9F%E9%80%9A%E8%AE%AF/">原生通讯 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E5%9F%BA%E7%A1%80/">基础 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E5%A4%8D%E5%88%A9%E6%95%88%E5%BA%94/">复利效应 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E5%AE%89%E8%A3%85%E6%95%99%E7%A8%8B/">安装教程 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E5%B0%91%E6%9C%89%E4%BA%BA%E8%B5%B0%E7%9A%84%E8%B7%AF/">少有人走的路 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E5%BF%83%E8%AF%AD/">心语 (3)</a></li>
    
    <li><a href="https://luckly.work/categories/%E6%8F%92%E4%BB%B6/">插件 (2)</a></li>
    
    <li><a href="https://luckly.work/categories/%E6%95%99%E5%AD%A6/">教学 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E7%8E%8B%E9%98%B3%E6%98%8E/">王阳明 (3)</a></li>
    
    <li><a href="https://luckly.work/categories/%E7%94%B5%E5%AD%90%E4%B9%A6/">电子书 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E7%99%BB%E9%99%86%E8%A1%A8%E5%8D%95/">登陆表单 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E7%A8%BB%E7%9B%9B%E5%92%8C%E5%A4%AB/">稻盛和夫 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E7%A9%B7%E7%88%B8%E7%88%B8%E5%AF%8C%E7%88%B8%E7%88%B8/">穷爸爸富爸爸 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E7%B2%BE%E8%BF%9B/">精进 (3)</a></li>
    
    <li><a href="https://luckly.work/categories/%E7%BC%96%E7%A8%8B/">编程 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E8%99%9A%E5%B9%BB/">虚幻 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E8%B4%A2%E5%8A%A1%E8%87%AA%E7%94%B1%E4%B9%8B%E8%B7%AF/">财务自由之路 (2)</a></li>
    
    <li><a href="https://luckly.work/categories/%E8%B7%91%E6%AD%A5/">跑步 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E8%B7%AF%E7%94%B1%E4%BC%A0%E5%8F%82/">路由传参 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E8%B7%AF%E7%BA%BF/">路线 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E8%BD%AF%E4%BB%B6%E5%AE%9E%E6%96%BD/">软件实施 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E9%98%B3%E6%98%8E%E5%BF%83%E5%AD%A6/">阳明心学 (3)</a></li>
    
    <li><a href="https://luckly.work/categories/%E9%A1%B9%E7%9B%AE/">项目 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E9%AD%85%E5%8A%9B/">魅力 (1)</a></li>
    
</ul>
    </section>

    <section class="widget">
        <h3 class="widget-title"><a href='/tags/'>标签</a></h3>
<div class="tagcloud">
    
    <a href="https://luckly.work/tags/flutter/">flutter</a>
    
    <a href="https://luckly.work/tags/IT/">IT</a>
    
    <a href="https://luckly.work/tags/Kotlin/">Kotlin</a>
    
    <a href="https://luckly.work/tags/Mysql/">Mysql</a>
    
    <a href="https://luckly.work/tags/nginx/">nginx</a>
    
    <a href="https://luckly.work/tags/Vue/">Vue</a>
    
    <a href="https://luckly.work/tags/YouTube%E8%A7%86%E9%A2%91%E4%B8%8B%E8%BD%BD/">YouTube视频下载</a>
    
    <a href="https://luckly.work/tags/android/">android</a>
    
    <a href="https://luckly.work/tags/dart/">dart</a>
    
    <a href="https://luckly.work/tags/flutter/">flutter</a>
    
    <a href="https://luckly.work/tags/gin/">gin</a>
    
    <a href="https://luckly.work/tags/git/">git</a>
    
    <a href="https://luckly.work/tags/go/">go</a>
    
    <a href="https://luckly.work/tags/gorm/">gorm</a>
    
    <a href="https://luckly.work/tags/grpc/">grpc</a>
    
    <a href="https://luckly.work/tags/html/">html</a>
    
    <a href="https://luckly.work/tags/ios/">ios</a>
    
    <a href="https://luckly.work/tags/linux/">linux</a>
    
    <a href="https://luckly.work/tags/nginx/">nginx</a>
    
    <a href="https://luckly.work/tags/python/">python</a>
    
    <a href="https://luckly.work/tags/redis/">redis</a>
    
    <a href="https://luckly.work/tags/%E4%B8%AA%E4%BA%BA%E8%B5%84%E6%96%99/">个人资料</a>
    
    <a href="https://luckly.work/tags/%E4%B9%A6%E5%8D%95/">书单</a>
    
    <a href="https://luckly.work/tags/%E4%B9%A6%E8%AF%84/">书评</a>
    
    <a href="https://luckly.work/tags/%E4%BF%A1%E6%81%AF%E7%B3%BB%E7%BB%9F%E7%AE%A1%E7%90%86%E5%B8%88/">信息系统管理师</a>
    
    <a href="https://luckly.work/tags/%E4%BF%A1%E6%81%AF%E7%B3%BB%E7%BB%9F%E9%A1%B9%E7%9B%AE%E7%AE%A1%E7%90%86%E5%B8%88/">信息系统项目管理师</a>
    
    <a href="https://luckly.work/tags/%E5%85%A5%E9%97%A8/">入门</a>
    
    <a href="https://luckly.work/tags/%E5%8E%9F%E5%88%99/">原则</a>
    
    <a href="https://luckly.work/tags/%E5%8E%9F%E7%94%9F%E9%80%9A%E8%AE%AF/">原生通讯</a>
    
    <a href="https://luckly.work/tags/%E5%9F%BA%E7%A1%80/">基础</a>
    
    <a href="https://luckly.work/tags/%E5%A4%8D%E5%88%A9%E6%95%88%E5%BA%94/">复利效应</a>
    
    <a href="https://luckly.work/tags/%E5%AE%89%E8%A3%85%E6%95%99%E7%A8%8B/">安装教程</a>
    
    <a href="https://luckly.work/tags/%E5%B0%91%E6%9C%89%E4%BA%BA%E8%B5%B0%E7%9A%84%E8%B7%AF/">少有人走的路</a>
    
    <a href="https://luckly.work/tags/%E5%BF%83%E8%AF%AD/">心语</a>
    
    <a href="https://luckly.work/tags/%E6%8F%92%E4%BB%B6/">插件</a>
    
    <a href="https://luckly.work/tags/%E6%95%99%E5%AD%A6/">教学</a>
    
    <a href="https://luckly.work/tags/%E7%8E%8B%E9%98%B3%E6%98%8E/">王阳明</a>
    
    <a href="https://luckly.work/tags/%E7%94%B5%E5%AD%90%E4%B9%A6/">电子书</a>
    
    <a href="https://luckly.work/tags/%E7%99%BB%E9%99%86%E8%A1%A8%E5%8D%95/">登陆表单</a>
    
    <a href="https://luckly.work/tags/%E7%A8%BB%E7%9B%9B%E5%92%8C%E5%A4%AB/">稻盛和夫</a>
    
    <a href="https://luckly.work/tags/%E7%A9%B7%E7%88%B8%E7%88%B8%E5%AF%8C%E7%88%B8%E7%88%B8/">穷爸爸富爸爸</a>
    
    <a href="https://luckly.work/tags/%E7%B2%BE%E8%BF%9B/">精进</a>
    
    <a href="https://luckly.work/tags/%E7%BC%96%E7%A8%8B/">编程</a>
    
    <a href="https://luckly.work/tags/%E8%99%9A%E5%B9%BB/">虚幻</a>
    
    <a href="https://luckly.work/tags/%E8%AF%97/">诗</a>
    
    <a href="https://luckly.work/tags/%E8%AF%BB%E4%B9%A6%E7%AC%94%E8%AE%B0/">读书笔记</a>
    
    <a href="https://luckly.work/tags/%E8%B4%A2%E5%8A%A1%E8%87%AA%E7%94%B1%E4%B9%8B%E8%B7%AF/">财务自由之路</a>
    
    <a href="https://luckly.work/tags/%E8%B7%91%E6%AD%A5/">跑步</a>
    
    <a href="https://luckly.work/tags/%E8%B7%AF%E7%94%B1%E4%BC%A0%E5%8F%82/">路由传参</a>
    
    <a href="https://luckly.work/tags/%E8%B7%AF%E7%BA%BF/">路线</a>
    
    <a href="https://luckly.work/tags/%E8%BD%AF%E4%BB%B6%E5%AE%9E%E6%96%BD/">软件实施</a>
    
    <a href="https://luckly.work/tags/%E9%80%9A%E8%AE%AF%E5%BD%95/">通讯录</a>
    
    <a href="https://luckly.work/tags/%E9%98%B3%E6%98%8E%E5%BF%83%E5%AD%A6/">阳明心学</a>
    
    <a href="https://luckly.work/tags/%E9%A1%B9%E7%9B%AE/">项目</a>
    
    <a href="https://luckly.work/tags/%E9%AD%85%E5%8A%9B/">魅力</a>
    
</div>
    </section>

    
<section class="widget">
    <h3 class="widget-title">友情链接</h3>
    <ul class="widget-list">
        
        <li>
            <a target="_blank" href="http://www.topgoer.com/" title="枯藤">枯藤</a>
        </li>
        
        <li>
            <a target="_blank" href="https://gorm.cn/zh_CN/docs/index.html" title="gorm">gorm</a>
        </li>
        
        <li>
            <a target="_blank" href="https://docs.python.org/zh-cn/3/tutorial/index.html" title="python">python</a>
        </li>
        
        <li>
            <a target="_blank" href="https://www.liwenzhou.com/" title="李文周">李文周的博客</a>
        </li>
        
        <li>
            <a target="_blank" href="http://www.xbzweb.com/" title="小包子的博客">小包子的博客</a>
        </li>
        
        <li>
            <a target="_blank" href="https://www.flysnow.org/" title="飞雪无情的博客">飞雪无情的博客</a>
        </li>
        
        <li>
            <a target="_blank" href="https://sliverhorn.com/" title="sliverhorn的博客">sliverhorn的博客</a>
        </li>
        
        <li>
            <a target="_blank" href="http://yuedu.baidu.com/ebook/14a722970740be1e640e9a3e" title="Android Gradle权威指南">Android Gradle权威指南</a>
        </li>
        
        <li>
            <a target="_blank" href="https://gesdh.cn/" title="小格子">格子导航</a>
        </li>
        
        <li>
            <a target="_blank" href="https://itachi.xyz/" title="阿林">itachi&#39;s Blog</a>
        </li>
        
        <li>
            <a target="_blank" href="https://darjun.github.io/" title="大俊">大俊Blog</a>
        </li>
        
        <li>
            <a target="_blank" href="https://geektutu.com/post/quick-golang.html" title="极客兔兔">极客兔兔Blog</a>
        </li>
        
        <li>
            <a target="_blank" href="http://zxfcumtcs.github.io/" title="赵雪峰">雪峰Blog</a>
        </li>
        
    </ul>
</section>


    <section class="widget">
        <h3 class="widget-title">其它</h3>
        <ul class="widget-list">
            <li><a href="https://luckly.work/index.xml">文章 RSS</a></li>
        </ul>
    </section>
</div>
            </div>
        </div>
    </div>
</body>

</html>